package com.vr.cloudpicture.manager.websocket.strategy;

import com.vr.cloudpicture.manager.websocket.model.enums.PictureEditMessageTypeEnum;
import com.vr.cloudpicture.manager.websocket.strategy.impl.EditActionMessageStrategy;
import com.vr.cloudpicture.manager.websocket.strategy.impl.EnterEditMessageStrategy;
import com.vr.cloudpicture.manager.websocket.strategy.impl.ErrorMessageStrategy;
import com.vr.cloudpicture.manager.websocket.strategy.impl.ExitEditMessageStrategy;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * 图片编辑消息策略工厂
 *
 * @author hzh
 * @date 2025/05/28
 */
@Component
@RequiredArgsConstructor
public class PictureEditMessageStrategyFactory {
    private final EnterEditMessageStrategy enterEditMessageStrategy;
    private final EditActionMessageStrategy editActionMessageStrategy;
    private final ExitEditMessageStrategy exitEditMessageStrategy;
    private final ErrorMessageStrategy errorMessageStrategy;

    private static final Map<String,PictureEditMessageStrategy> STRATEGIES =new HashMap<>();
    @PostConstruct
    public void init() {
        STRATEGIES.put(PictureEditMessageTypeEnum.ENTER_EDIT.getValue(),enterEditMessageStrategy);
        STRATEGIES.put(PictureEditMessageTypeEnum.EDIT_ACTION.getValue(),editActionMessageStrategy);
        STRATEGIES.put(PictureEditMessageTypeEnum.EXIT_EDIT.getValue(),exitEditMessageStrategy);
    }

    /**
     * 根据消息类型获取不同的策略
     *
     * @param type 类型
     * @return {@code PictureEditMessageStrategy }
     */
    public PictureEditMessageStrategy getStrategyByMessageType(String type) {
        return STRATEGIES.getOrDefault(type,errorMessageStrategy);
    }


}
